package ferp.core.calc.scorer;

import ferp.core.calc.Calculator;
import ferp.core.game.Game;
import ferp.core.game.Settings;
import ferp.core.player.Player;

/**
 * User: olegs
 * Date: 12/3/13 2:12 PM
 */
public class Tricking10 extends Scorer
{
  public static final Tricking10 instance = new Tricking10();

  @Override
  protected void update(Game g, Settings settings, Calculator c)
  {
    if (g.getDeclarerTricks() == Game.MAXIMUM_TRICKS)
      c.writeToPool(g, settings, g.declarer(), c.getPlayCostSuccess(g.contract()));
    else
    {
      int cost = c.getPlayCostFailure(g.contract());
      int missedTricks = Game.MAXIMUM_TRICKS - g.getDeclarerTricks();
      Player declarer = g.declarer();
      Player p1 = g.previous(declarer);
      Player p2 = g.next(declarer);

      c.writeToMountain(g, declarer, cost * missedTricks);
      c.writeToWhists(g, p1, declarer, cost * missedTricks);
      c.writeToWhists(g, p2, declarer, cost * missedTricks);
    }
  }

  @Override
  protected void statistics(Game g)
  {
    g.statistics.updateTricking(g.declarer().id(), g.contract(), g.getDeclarerTricks());
  }
}
